

    //
//  NewsCell.m
//  掌上宏力
//
//  Created by admin on 17/3/3.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "NewsItem.h"
#import "CommonNews.h"

@implementation NewsItem

-(void)updateCellInfoWith:(id)data index:(NSInteger)index{
    self.backgroundColor = [UIColor whiteColor];
    
    CommonNews *news = (CommonNews*)data;
    for (UIView *View in self.subviews) {
        [View removeFromSuperview];
    }
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, kScreenW-50, 40)];
    title.text = [NSString stringWithFormat:@"%ld.  %@",(long)++index,news.title];
    title.numberOfLines = 0;
    title.font = kFont(16);
    title.textColor = [UIColor darkTextColor];
    [self addSubview:title];
    
    /*{\"id\":14355,\
     "HEADER\":\"河南宏力学校每周例会纪要\",\
     "FB_DATE\":\"2017/4/8 0:00:00\"}
     */
    NSDateFormatter *f =[NSDateFormatter new];
    f.dateFormat = @"yyyy/MM/dd HH:mm:ss";
    NSDate *date = [f dateFromString:news.date];
    NSDateFormatter *f2 = [NSDateFormatter new];
    f2.dateFormat = @"yyyy-MM-dd";
    NSString *fb_date = [f2 stringFromDate:date];
    NSString *today = [f2 stringFromDate:[NSDate date]];
    
    NSDate *yesDate = [NSDate dateWithTimeIntervalSinceNow:-(24*60*60)];
    NSString *yestoday = [f2 stringFromDate:yesDate];
    
    NSString *showTime = fb_date;
    UILabel *timeLab = [[UILabel alloc] initWithFrame:CGRectMake(kScreenW-120, 45, 100, 20)];
    timeLab.font = kFont(13);
    if ([fb_date isEqualToString:today]) {
        showTime = @"今天";
        timeLab.textColor = [UIColor redColor];
        timeLab.font = kFont(14);
    }else if ([fb_date isEqualToString:yestoday]) {
        showTime = @"昨天";
        timeLab.textColor = [UIColor redColor];
        timeLab.font = kFont(14);
    }
    timeLab.text = showTime;
    timeLab.textAlignment = NSTextAlignmentRight;
    [self addSubview:timeLab];

}


@end
